package com.funtl.framework.web.service.purview.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.funtl.framework.java.exception.DaoException;
import com.funtl.framework.java.exception.ServiceException;
import com.funtl.framework.java.orm.hibernate.service.IHibernateDao;
import com.funtl.framework.web.entity.PurviewGroup;
import com.funtl.framework.web.service.purview.IPurviewGroupService;

@Component
public class PurviewGroupServiceImpl implements IPurviewGroupService {
	private IHibernateDao hibernateDao;
	
	//service
	
	@Override
	public void insertAll(String managerId, List<PurviewGroup> groups) throws ServiceException {
		try {
			hibernateDao.excuteSQL("DELETE FROM t_purview_group WHERE purview_manager_id = ?", new String[] {managerId});
			if (groups != null && groups.size() > 0) {
				hibernateDao.insertAll(groups);
			}
		} catch (DaoException e) {
			throw new ServiceException("insertAll", e);
		}
	}
	
	@Override
	public List<String> queryMenus(String managerId) throws ServiceException {
		List<String> menus = null;
		List<Map<String, Object>> list = hibernateDao.getListBySQL("SELECT purview_menu_id FROM t_purview_group WHERE purview_manager_id = ?", new String[] {managerId});
		if (list != null && list.size() > 0) {
			menus = new ArrayList<String>();
			for (Map<String, Object> map : list) {
				menus.add(String.valueOf(map.get("purview_menu_id")));
			}
		}
		return menus;
	}
	
	//common service

	@Override
	public PurviewGroup get(PurviewGroup entity) throws ServiceException {
		return null;
	}

	@Override
	public Long getCount(PurviewGroup entity) throws ServiceException {
		return null;
	}

	@Override
	public List<PurviewGroup> getList(PurviewGroup entity) throws ServiceException {
		return null;
	}

	@Override
	public String insert(PurviewGroup entity) throws ServiceException {
		return null;
	}

	@Override
	public String delete(PurviewGroup entity) throws ServiceException {
		return null;
	}

	@Override
	public String update(PurviewGroup entity) throws ServiceException {
		return null;
	}

	@Override
	public List<PurviewGroup> page(PurviewGroup entity) throws ServiceException {
		return null;
	}
	
	//getter setter
	
	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}

	@Resource
	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

}
